//
//  DebugMainItemCell.swift
//  YKSwiftDebugManager
//
//  Created by linghit on 2021/12/2.
//

import UIKit

class DebugMainItemCell: DebugBaseCollectionViewCell {
    
    private lazy var itemImageView:UIImageView = {
        let imageView = UIImageView.init(frame: CGRect(x: 30, y: 10, width: self.bounds.size.width - 60, height: self.bounds.size.width - 60))
        imageView.contentMode = .scaleAspectFit

        if #available(iOS 13.0, *) {
            imageView.backgroundColor = UIColor.init(dynamicProvider: { traitCollection in
                if traitCollection.userInterfaceStyle == .light{
                    return UIColor.clear
                }else{
                    return UIColor.lightGray
                }
            })
        } else {
            imageView.backgroundColor = UIColor.clear
        }
        imageView.clipsToBounds = true
        return imageView
    }()
    
    private lazy var itemLabel:UILabel = {
        let label = UILabel.init(frame: CGRect(x: 0, y: self.itemImageView.frame.maxY, width: self.bounds.size.width, height: 20))
        label.font = UIFont.systemFont(ofSize: 12)
        
        if #available(iOS 13.0, *) {
            label.textColor = .label
        } else {
            label.textColor = .black
        }
        label.textAlignment = .center
        
        return label
    }()
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        setupUI()
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    func setupUI()->Void{
        self.addSubview(itemImageView)
        self.addSubview(itemLabel)
    }
    
    override func detail(indexPath: IndexPath) {
        super.detail(indexPath: indexPath)
        DebugManagerUtil.share.getCustomItem(indexPath: indexPath) { itemImage, titleStr in
            
            self.itemImageView.image = itemImage
            self.itemLabel.text = titleStr
        }
    }
}
